<template>
  <div>
    <el-menu
      class="el-menu-vertical-demo"
      :collapse="isCollapse"
      background-color="#545c64"
      text-color="white"
      :style="`border:none;height:${screenHeight}`"
    >
      <h4 style="text-align: center; color: white; margin-top: 10px">
        {{ isCollapse ? "后台" : "后台管理系统" }}
      </h4>
      <el-menu-item
        v-for="item in nochildren"
        :index="item.path+''"
        :key="item.path"
        @click="pushto(item)"
      >
        <i :class="'el-icon-' + item.icon"></i>
        <span slot="title">{{ item.label }}</span>
      </el-menu-item>
      <el-submenu
        v-for="item in haschildren"
        :index="item.path+''"
        :key="item.path"
      >
        <template slot="title">
          <i :class="'el-icon-' + item.icon"></i>
          <span slot="title">{{ item.label }}</span>
        </template>
        <el-menu-item
          v-for="item in haschildren[0].children"
          :index="item.path+''"
          :key="item.path"
          @click="pushto(item)"
        >
          <template slot="title">
            <i :class="'el-icon-' + item.icon"></i>
            <span slot="title">{{ item.label }}</span>
          </template>
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      items: [
        // {
        //   path: "/",
        //   name: "home",
        //   label: "首页",
        //   icon: "s-home",
        //   url: "Home/Home",
        // },
        // {
        //   path: "/goods",
        //   name: "goods",
        //   label: "商品管理",
        //   icon: "video-play",
        //   url: "MallManage/MallMange",
        // },
        // {
        //   path: "/users",
        //   name: "users",
        //   label: "用户管理",
        //   icon: "user",
        //   url: "UserManage/UserManage",
        // },
        // {
        //   path: "other",
        //   label: "其他",
        //   icon: "location",
        //   children: [
        //     {
        //       path: "/page1",
        //       name: "page1",
        //       label: "页面1",
        //       icon: "setting",
        //       url: "Other/PageOne",
        //     },
        //     {
        //       path: "/page2",
        //       name: "page2",
        //       label: "页面2",
        //       icon: "setting",
        //       url: "Other/PageTwo",
        //     },
        //   ],
        // },
      ],
    };
  },
  computed: {
    haschildren() {
      return this.asyncMenu.filter((item) => item.children);
    },
    nochildren() {
      return this.asyncMenu.filter((item) => !item.children);
    },
    screenHeight() {
      return (
        (window.innerHeight || document.documentElement.clientHeight) + "px"
      );
    },
    asyncMenu() {
      return this.$store.state.tabs.menu
    },
    ...mapState("infoCollapse", ["isCollapse"]),
  },
  methods: {
    pushto(value) {
        this.$router.push({
          name: value.name,
        }).catch(err=>err)
        this.$store.commit('tabs/selectMenu',value)
    },
  },
};
</script>

<style scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>